package com.demo.listener;

import com.demo.bean.User;

import java.io.IOException;

@javax.servlet.annotation.WebServlet(name = "LoginServlet", urlPatterns = "/login.do")
public class LoginServlet extends javax.servlet.http.HttpServlet {
    @Override
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {

    }

    @Override
    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");

        //模拟登陆校验
        if ("admin".equals(username) && "123".equals(password)) {
            User user = new User(username, password);
            request.getSession().setAttribute("user", user);
            request.getRequestDispatcher("/login_success.jsp").forward(request, response);
        } else {
            response.sendRedirect("/Demo0312/login.html");
        }
    }
}
